var generate_imgurl=new Object;
//生成作品原版大图
function generate_picture(w_id,original,workno,bgshow,qr_code){	//bgshow 是否加载背景图到canvas,qr_code是否添加二维码（增加canvas高度）

	generate_imgurl[w_id]=new Object;	
	generate_imgurl[w_id].base64image=new Array;
	if(workno==-1){		
		for(var i=0; i<UtilProperty[w_id].worker.length;i++){
			sigeritem(w_id,i,original,bgshow,qr_code);
		}
	}else{	
		sigeritem(w_id,workno,original,bgshow,qr_code)
	}
	
}


function sigeritem(w_id,i,original,bgshow,qr_code){//qr_code为true时要增加canvas的高度
	var item=UtilProperty[w_id].worker[i];					
	var canvas=document.createElement("canvas");						
	var context=canvas.getContext("2d");
	var w=maxScreen.width;
	var h=maxScreen.height;
	var scale=1;
	var scale;		
	if(item.width / item.height > w / h) {
		scale=w/item.width;
	} else {
		scale=h/item.height;
	}
	
	
	canvas.height=item.height*scale;
	canvas.width=item.width*scale;	
	canvas.setAttribute('style','width:'+canvas.width/Pixel_Ratio+'px; height:'+canvas.height/Pixel_Ratio+'px;');
	if(bgshow){
		//给相应的作品添加背景图片
		context.rect(0, 0, item.width, item.height);
		context.fillStyle = '#ffffff';
		context.fill();	
		context.save();	
		context.closePath();		
		layoutbackground(item,context,canvas.width,canvas.height,scale);
	}
	
	
	drawToCanvas(w_id,canvas,i,item,context,scale,true,original);
	
	var canurl;
	if(bgshow){
		canurl=canvas.toDataURL("image/jpeg");
	}else{
		canurl=canvas.toDataURL();
	}
	var obj={title:item.title,pageid:item.id,imgurl:canurl};
	generate_imgurl[w_id].base64image.push(obj);
	
	if(qr_code){
		var len=generate_imgurl[w_id].base64image.length;
		qr_codeTocanvas(canvas,scale,w_id,len);
	}
	
	
}

var qr_codeobj;//存储二维码的信息
//增加二维码 带文字
/*function qr_codeTocanvas(canvas,scale,w_id,len){
	
		var qr_canvas=document.createElement("canvas");						
		var qr_context=qr_canvas.getContext("2d");
		qr_canvas.height=canvas.height+qr_codeobj.height*scale;
		qr_canvas.width=canvas.width;
		
		qr_context.beginPath();
		qr_context.rect(0, 0, qr_canvas.width, qr_canvas.height);
		qr_context.fillStyle = 'rgba(250,250,250,1)';
		qr_context.fill();	
		qr_context.save();	
		qr_context.closePath();
		
		qr_context.beginPath();
		qr_context.clearRect(0, 0, qr_canvas.width, canvas.height);
		qr_context.rect(0, 0, qr_canvas.width, canvas.height);
		qr_context.save();
		qr_context.clip();
		qr_context.drawImage(canvas,0,0,canvas.width, canvas.height);
		qr_context.restore();
		
		qr_context.beginPath();
		var _h=qr_codeobj.height*scale;
		qr_context.clearRect(0, canvas.height, qr_canvas.width,_h );
		qr_context.rect(0, canvas.height, qr_canvas.width,_h);
		qr_context.save();
		qr_context.clip();
		if(qr_codeobj){
			qr_context.drawImage(qr_codeobj,0, canvas.height, qr_canvas.width,_h);
		}		
		qr_context.restore();
		
		var qrurl=qr_canvas.toDataURL("image/jpeg");
		generate_imgurl[w_id].base64image[len-1].imgurl=qrurl;
	
	
	
}
*/
//增加二维码 
function qr_codeTocanvas(canvas,scale,w_id,len){
	
		var qr_canvas=document.createElement("canvas");						
		var qr_context=qr_canvas.getContext("2d");
		qr_canvas.height=canvas.height;
		qr_canvas.width=canvas.width;
		
		qr_context.beginPath();
		qr_context.rect(0, 0, qr_canvas.width, qr_canvas.height);
		qr_context.fillStyle = '#ffffff';
		qr_context.fill();	
		qr_context.save();	
		qr_context.closePath();
		
		qr_context.beginPath();
		qr_context.clearRect(0, 0, qr_canvas.width, canvas.height);
		qr_context.rect(0, 0, qr_canvas.width, canvas.height);
		qr_context.save();
		qr_context.clip();
		qr_context.drawImage(canvas,0,0,canvas.width, canvas.height);
		qr_context.restore();
		
		qr_context.beginPath();
		var _h=qr_codeobj.height*scale;
		var _w=qr_codeobj.width*scale;
		var _x=qr_canvas.width-_w-20;
		var _y=canvas.height-_h-20;
		qr_context.clearRect(_x, _y, _w,_h );
		qr_context.rect(_x, _y, _w,_h );
		qr_context.save();
		qr_context.clip();
		if(qr_codeobj){
			qr_context.drawImage(qr_codeobj,_x, _y, _w,_h );
		}		
		qr_context.restore();
		
		var qrurl=qr_canvas.toDataURL("image/jpeg");
		generate_imgurl[w_id].base64image[len-1].imgurl=qrurl;
	
	
	
}
